<template>
  <div class="navbar">
    <router-link to="/create-profile">创建宠物档案</router-link>
    <router-link to="/view-profile">查看宠物档案</router-link>
    <router-link to="/chat">宠物聊天</router-link>
    <router-link to="/diary">宠物日记</router-link>
    <el-button type="danger" @click="logout" class="logout-button">退出登录</el-button>
  </div>
</template>

<script>
export default {
  name: 'Navbar',
  methods: {
    logout() {
      localStorage.removeItem('token');
      if (this.$route.path !== '/login') {
        this.$router.push('/login'); // 跳转到登录页面
      }
    }
  }
};
</script>

<style scoped>
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background-color: #f2f2f2;
}

.navbar a {
  text-decoration: none;
  color: #333;
  padding: 10px;
  border-radius: 5px;
  transition: background-color 0.3s;
}

.navbar a:hover {
  background-color: #ddd;
}

.logout-button {
  margin-left: auto;
  color: white;
}
</style>
